home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 8343 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.8 KB

  1. Path: admaix.sunydutchess.edu!ub!newserve!rebecca!rpi!not-for-mail
  2. From: miker3@ix.netcom.com (Mike Rubenstein)
  3. Newsgroups: comp.lang.c++.moderated,comp.lang.c++
  4. Subject: Re: enum expression is IF statement
  5. Date: 16 Feb 1996 23:51:29 -0000
  6. Organization: Netcom
  7. Sender: cppmods@netlab.cs.rpi.edu
  8. Approved: vandevod@cs.rpi.edu
  9. Message-ID: <4g35a1$5r9@netlab.cs.rpi.edu>
  10. References: <4fq7dc$pac@netlab.cs.rpi.edu> <4g1pj9$pqg@netlab.cs.rpi.edu>
  11. NNTP-Posting-Host: netlab.cs.rpi.edu
  12. X-Original-Date: Fri, 16 Feb 1996 23:06:26 GMT
  13.  
  14. gstern@earth.usa.net (Greg Sternberg/PDS Inc) wrote:
  15.  
  16. > Peter van Klaveren (P.v.Klaveren@bcs.cs.philips.com) wrote:
  17. > : enum
  18. > : {
  19. > :    CSEQ_IDLE,
  20. > :    CSEQ_ERROR,
  21. > :    CSEQ_ABORT,
  22. > :    CSEQ_WAIT4RESPONSE
  23. > : };
  24. > : int state = 3;
  25. > : if (state == CSEQ_WAIT4RESPONSE)
  26. > : {
  27. > :     // this code is not executed!!!
  28. > :     ...
  29. > : }
  30. >    You're making the assumption that the compiler is numbering your enums
  31. >    sequentially from 0 - since the standard says nothing about how the
  32. >    compiler could number your enums it could very well be using 0x1, 0x2, 
  33. >    0x4, and 0x8.
  34.  
  35. From draft 7.2:
  36.  
  37.     The identifiers in an enumerator-list are declared as
  38.     constants, and can  appear  wherever  constants  are  
  39.     required.  If no enumerator-definitions with = appear, then
  40.     the values of the corresponding constants begin at zero and
  41.     increase by one as the enumerator-list is read from left to
  42.     right.
  43.  
  44. The C standard (ISO 6.5.2.2) and ARM (7.2) also require this.
  45.  
  46.  
  47. Michael M Rubenstein
  48.  
  49.       [ Articles to moderate: mailto:c++-submit@netlab.cs.rpi.edu ]
  50.       [  Read the C++ FAQ: http://www.connobj.com/cpp/cppfaq.htm  ]
  51.       [  Moderation policy: http://www.connobj.com/cpp/guide.htm  ]
  52.       [      Comments? mailto:c++-request@netlab.cs.rpi.edu       ]
  53.